﻿using System;
using System.Windows;
using System.Windows.Data;

namespace AEM.Converters
{
    [ValueConversion(typeof(int), typeof(string))]
    public class PermissionToStringConverter : IValueConverter
    {
        public static PermissionToStringConverter Instance = new PermissionToStringConverter();

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (null == value) return "";
            string permission = "";
            long power = (long)value;
            foreach (Data.Enum.ControlPoints p in Enum.GetValues(typeof(Data.Enum.ControlPoints)))
            {
                if (((int)p & power) > 0) permission += (string)Application.Current.TryFindResource(p.ToString()) + ",";
            }
            return permission;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
